<?php

namespace App\Listeners;

use App\Events\ApproveOperate as ApproveEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;

class ApproveOperate implements ShouldQueue {
	/**
	 * Create the event listener.
	 *
	 * @return void
	 */
	public function __construct() {
		//
	}

	/**
	 * Handle the event.
	 *
	 * @param  object  $event
	 * @return void
	 */
	public function handle(ApproveEvent $event) {
		$item_id = $event->item_id;
		if (\Auth::user()->isApproveing($item_id)) {
			DB::table('items')->where('id', $item_id)->increment('approve_nums');
		} else {
			DB::table('items')->where('id', $item_id)->decrement('approve_nums');
		}
	}
}
